from pydantic import BaseSettings
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base


class Settings(BaseSettings):
    DB_CONNECTION: str
    DB_HOST: str
    DB_PORT: str
    DB_DATABASE: str
    DB_USERNAME: str
    DB_PASSWORD: str

    class Config:
        env_file = "app/.env"
        encoding = "utf-8"

def get_conn_str():
    s = Settings()
    return f"{s.DB_CONNECTION}://{s.DB_USERNAME}:{s.DB_PASSWORD}@{s.DB_HOST}:{s.DB_PORT}/{s.DB_DATABASE}"

engine = create_engine(get_conn_str())
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
